//
//  CZVistorTableViewController.swift
//  weibo
//
//  Created by Apple on 16/3/9.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class CZVistorTableViewController: UITableViewController, CZVistorViewDelegate {

    //  登录的是否成功的标记,判断accesstoken是否存在，存在就是登录了（暂时这样写，后面加上时间判断）
    var userLogin = CZUserAccountViewModel.sharedAccount.userLogin//CZUserAccountViewModel.sharedAccount.accessToken != nil //false//CZUserAccountViewModel.sharedAccount.userAccount?.access_token != nil
    //  访客视图
    var visitorView: CZVistorView?
    
    //  捕获是否登录
    override func loadView() {
        
        userLogin ? super.loadView() : loadVisitorView()
        
    }
    
    private func loadVisitorView() {
        visitorView = CZVistorView()
        //  设置代理
        visitorView?.delegate = self
        //  设置访客视图颜色
        visitorView?.backgroundColor = UIColor(white: 237 / 255, alpha: 1)
        view = visitorView
        
        //  未登录情况下，导航栏显示登录和注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "loginAction")
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    // MARK:    点击事件
    @objc private func loginAction() {
        
        print("点击了登录或者注册")
        presentVC()
        
    }
    
    // MARK:    访客视图代理
    func registerButtonSelected() {
        print("点击了注册")
        presentVC()
    }
    
    func loginButtonSelected() {
        print("点击了登录")
        presentVC()
    }
    
  
    private func presentVC() {
    
        let navVC = UINavigationController(rootViewController: CZOAuthViewController())
        presentViewController(navVC, animated: true, completion: nil)
    }

  
}
